@extends('public.base')
@section('body')
    <style>
        .layui-unselect dl {
            max-height: 160px;
        }

        html {
            background-color: #fff;
        }
        .class-img:hover a.del { color: #27A9E3; border-color: #27A9E3;border: 1px solid #f00; display: block;}
        .class-img  a.del {     font-family: Tahoma;
            font-size: 10px;
            line-height: 14px;
            color: #CCC;
            background-color: #FFF;
            vertical-align: middle;
            text-align: center;
            display: none;
            width: 18px;
            height: 18px;
            border: solid 1px;
            border-radius: 8px;
            z-index: 2;
            top: 1px;
            right: 3px;
        }
    </style>
    <div class="layui-row">
        <form id="main_form" class="layui-form layui-form-pane" action="" method="post" lay-filter="main-form-group">
            <!-- ==================================  隐藏区  ================================== -->
            <input type="hidden" name="id" value="">

            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-tab layui-tab-card" lay-filter="tab_form">
                        <ul class="layui-tab-title">

                            <li>内容提交1</li>
                            <li>其它附属</li>
                        </ul>
                        <div class="layui-tab-content">



                            <!-- 第二个选项卡内容 -->
                            <div class="layui-tab-item layui-show">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">下单时间</label>
                                    <div class="layui-input-block">
                                        <input type="text" class="layui-input" id="start_time" name="add_time"
                                               lay-verType="tips"
                                               autocomplete="off"
                                               format="date" value="{{date("Y-m-d H:i:s",$info->add_time)}}" placeholder="开始时间">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-inline" style="width: 260px;">
                                        <label class="layui-form-label">总金额</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="all_amount" id="all_amount" lay-verify="required" autocomplete="off"
                                                   placeholder="请输入总金额"
                                                   class="layui-input" value="{{$info->all_amount}}">
                                        </div>
                                    </div>
                                    <div class="layui-input-inline" style="width: 260px;">
                                        <label class="layui-form-label">实收金额</label>
                                        <div class="layui-input-block" >
                                            <input type="text" name="paid_amount" id="paid_amount" lay-verify="required" autocomplete="off"
                                                   placeholder="请输入实收金额"
                                                   class="layui-input" value="{{$info->paid_amount}}">
                                        </div>
                                    </div>

                                    <div class="layui-input-inline" style="width: 260px;">
                                        <label class="layui-form-label">代收金额</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="collected_amount" id="collected_amount" lay-verify="required" autocomplete="off"
                                                   placeholder="请输入代收金额"
                                                   class="layui-input" value="{{$info->collected_amount}}">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline" style="width: 260px;">
                                        <label class="layui-form-label">购买次数</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="buy_num" lay-verify="required" autocomplete="off"
                                                   placeholder="请输入购买次数"
                                                   class="layui-input" value="{{$info->buy_num}}">
                                        </div>
                                    </div>
                                    <div class="layui-input-inline" style="width: 260px;">
                                        <label class="layui-form-label">微信号</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="wx_no" value="{{$info->wx_name}}" placeholder="微信号或是名称" id="tags" class="layui-input">
                                            <span id="buy_select_no_text" style="color:red"><input type="hidden" name="wx_no" value="{{$info->wx_no}}"  class="layui-input"   /></span>
                                        </div>
                                    </div>

                                    <div class="layui-input-inline" style="width: 260px;">
                                        <label class="layui-form-label">销售员</label>
                                        <div class="layui-input-block">
                                            <select name="sale_id" class="form-control ">
                                                <option value="">
                                                    请选择
                                                </option>
                                                @foreach($memberList as $k=>$v)
                                                    <option value="{{$v->uid}}" @if($v->uid==$info->sale_id) selected="selected" @endif> {{$v->nickname}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline" style="width: 260px;">
                                        <label class="layui-form-label">快递类型</label>
                                        <div class="layui-input-block">
                                            <select  name="express_type">
                                                <option value="">选择快递</option>
                                                @foreach($shippingList  as $k=>$v)
                                                    <option value="{{$v['title']}}" @if($v->title==$info->express_type) selected="selected" @endif>{{$v['title']}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-input-inline" style="width: 260px;">
                                        <label class="layui-form-label">姓名</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="receiver" lay-verify="required" autocomplete="off"
                                                   placeholder="请输入收货姓名"
                                                   class="layui-input" value="{{$info->receiver}}">
                                        </div>
                                    </div>
                                    <div class="layui-input-inline" style="width: 260px;">
                                        <label class="layui-form-label">手机号</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="receiver_tel" lay-verify="required" autocomplete="off"
                                                   placeholder="请输入收货手机号"
                                                   class="layui-input" value="{{$info->receiver_tel}}">
                                        </div>
                                    </div>

                                </div>






                                <div class="layui-form-item">
                                    <div class="layui-input-inline" style="width: 260px;">
                                        <label class="layui-form-label">省份</label>
                                        <div class="layui-input-block">
                                            <select  name="receiver_province" class="province_select"  lay-filter="country">
                                                <option value="">请选择省</option>
                                                @foreach($areaList  as $k=>$v)
                                                    <option value="{{$v['area_id']}}"   @if($v->area_id==$info->receiver_province) selected="selected" @endif>{{$v['title']}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-input-inline" style="width: 260px;">
                                        <label class="layui-form-label">市</label>
                                        <div class="layui-input-block" >
                                            <select  name="receiver_city" id="city_id" lay-filter="city">
                                                <option value="">选择市</option>
                                                <option value="{{$info->receiver_city}}"    selected="selected" >{{$info->express->city_name}}</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="layui-input-inline" style="width: 260px;">
                                        <label class="layui-form-label">区</label>
                                        <div class="layui-input-block">
                                            <select  name="receiver_area" class="region_id" id="region_id">
                                                <option value="">选择县/区</option>
                                                <option value="{{$info->receiver_area}}"    selected="selected" >{{$info->express->region_name}}</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">


                                        <label class="layui-form-label">地址</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="receiver_addr" lay-verify="required" autocomplete="off"
                                                   placeholder="请输入标题"
                                                   class="layui-input" value="{{$info->receiver_addr}}">
                                        </div>


                                </div>


                                <div class="layui-form-item ">
                                    <div class="layui-input-inline" style="width: 200px;border-color: #e6e6e6;    border-width: 1px;">
                                      <label class="layui-form-label">粉丝类型</label>
                                        <div class="layui-input-block">
                                            <select  name="add_fen_type" class="fen" >
                                                <option value="新粉"   @if($v->add_fen_type=="新粉") selected="selected" @endif>新粉</option>
                                                <option value="老粉"   @if($v->add_fen_type=="老粉") selected="selected" @endif>老粉</option>
                                                <option value="复购"   @if($v->add_fen_type=="复购") selected="selected" @endif>复购</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-input-inline" style="width: 200px;border-color: #e6e6e6;    border-width: 1px;">
                                        <label class="layui-form-label">本月粉丝</label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" @if($info->add_fen_month==1) checked="" @endif  name="add_fen_month"
                                                   lay-skin="switch" lay-text="本月|非本月" value="1">
                                        </div>
                                    </div>


                                    <div class="layui-input-inline" style="width: 200px;border-color: #e6e6e6;    border-width: 1px;">
                                        <label class="layui-form-label">付款类型</label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" @if($info->pt_name==1) checked="" @endif name="pt_name"
                                                   lay-skin="switch" lay-text="全款|到付" value="1">
                                        </div>
                                    </div>
                                    <div class="layui-input-inline" style="width: 220px;">
                                        <label class="layui-form-label">付款方式</label>
                                        <div class="layui-input-block">
                                            <select  name="pay_type">
                                                <option value="">选择付款方式</option>
                                                @foreach($paytypeList  as $k=>$v)
                                                    <option value="{{$v['title']}}" @if($v->title==$info->pay_type) selected="selected" @endif>{{$v['title']}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>

                                </div>

                            </div>


                            <!--第三选卡--->
                            <div class="layui-tab-item">

                                <div class="layui-form-item">
                                    <label class="layui-form-label">充值会员</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="pay_username" id="username"
                                               placeholder="请输入名称"
                                               autocomplete="off" value="{{$info->pay_username}}" class="layui-input">
                                        <input type="hidden" name="pay_uid"  id="user_id" value="{{$info->pay_uid}}"/>
                                    </div>
                                    <button type="button" class="layui-btn layui-btn-primary"
                                            id="icon_select">
                                        <i class='layui-icon layui-icon-search'></i>
                                    </button>
                                </div>

                                    <div class="layui-form-item layui-form-text">
                                        <label class="layui-form-label">备注</label>
                                        <div class="layui-input-block">
                                            <textarea name="remark" placeholder="请输入其它信息"  lay-verify="required" class="layui-textarea">{{$info->remark}}</textarea>
                                        </div>
                                    </div>

                                <div class="layui-card">
                                    <div class="layui-card-header">上传多张图片</div>
                                    <div class="layui-card-body">
                                        <div class="layui-upload">
                                            <button type="button" class="layui-btn" id="test-upload-more">多图片上传    </button>
                                            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                                预览图：
                                                <div class="layui-upload-list" id="test-upload-more-list">
                                                    <?php
                                                    if(!empty($info->smeta)){
                                                        $arr=explode(",",$info->smeta);
                                                        foreach($arr as $k=>$v){
                                                            echo '<div class="class-img"><img src="'.$v.'" alt="'.$v.'" class="layui-upload-img"><a href="javascript:void(0)" class="del"   title="移除" delid="'.$v.'">X</a></div>';
                                                        }
                                                    }
                                                    ?>
                                                </div>
                                            </blockquote>
                                            <input type="hidden" name="smeta" id="smeta" value=" {{$info->smeta}}" />
                                        </div>
                                    </div>
                                </div>
                            </div>


                        </div>
                    </div>
                    <div class="layui-form-item layui-layout-admin" style="display: none">
                        <div class="layui-input-block">
                           <input type="hidden" name="id" value="{{$info->id}}" />
                            <div class="layui-footer" style="left: 0;">
                                <button id="form_save" lay-filter="form_save" class="layui-btn"
                                        lay-submit="">
                                    保存
                                </button>
                                <button id="form_reset" type="button" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </div>
                    <!-- 按钮区 -->

                </div>
            </div>
        </form>
    </div>
    <link rel="stylesheet" href="{{ADMIN_PATH}}jqueryui/jquery-ui.css">
    <script src="{{ADMIN_PATH}}/lib/jquery-2.1.0.js"></script>
    <script src="{{ADMIN_PATH}}/lib/jquery-migrate-1.2.1.min.js"></script>
    <script src="{{ADMIN_PATH}}jqueryui/jquery-ui-1.10.3.min.js"></script>
    <script src="{{ADMIN_PATH}}layui/layuiadmin/layui/layui.js"></script>
    <script src="{{ADMIN_PATH}}js/admin.common.js"></script>
    <script>

        var index_url = '{{url('admin/ordersys/order/set_step2')}}';
        var save_url = '{{url('admin/ordersys/order/mygoods/edit')}}';
        var select_user_url='{{url('admin/ordersys/customer/user_list')}}';
        var like_url = '{{url('admin/ordersys/vip/like')}}';
        var up_url = '{{url('public/upload/pic')}}';
        layui.use(['layer', 'laydate', 'table', 'element', 'form'], function () {
            var table = layui.table
                , $ = layui.$
        , form = layui.form;
            var $ = layui.jquery;
            table.render({
                elem: '#cart-table'
                , method: 'post' //接口http请求类型
                ,url: index_url
                ,cols: [[
                    {field:'goods_id', title: '产品ID', width:80}
                    ,{field:'goods_name', title: '产品名称', width:260}
                    ,{field:'goods_price', title: '产品价格', width:100}
                    ,{field:'goods_num', title: '产品数量', width:100}
                    ,{field:'unit', title: '产品单位', width:100}
                    ,{field:'goods_image', title: '小计', width:100, templet:function(d){
                        return (d.goods_price*d.goods_num).toFixed(2);
                        }}
                ]]
            });

            /* 监听提交 */
            form.on('submit(form_save)', function(data){
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                $.post(save_url, data.field, function (res) {
                    try {
                        if(res.status==200) {

                            //重新刷新父窗口的数据区
                            layer.msg(res.message);
                            parent.layer.close(index);
                            parent.location.reload();
                            // setTimeout(function () {
                            //     parent.layui.table.reload('main_table'); //重载表格
                            //     parent.layer.close(index); //再执行关闭
                            //     parent.$("#all_money").text('0.00');
                            //     parent.location.reload();
                            // }, 2000);

                        }else{
                            layer.msg(res.message);
                        }
                    } catch (e) {
                        layer.msg("异常");
                    }

                }, "json");

                return false;
            });

            //监听单元格事件
            table.on('tool(test-table-demoEvent)', function(obj){
                var data = obj.data;
                if(obj.event === 'setSign'){
                    layer.prompt({
                        formType: 2
                        ,title: '修改 ID 为 ['+ data.id +'] 的用户签名'
                        ,value: data.sign
                    }, function(value, index){
                        layer.close(index);

                        //这里一般是发送修改的Ajax请求

                        //同步更新表格和缓存对应的值
                        obj.update({
                            sign: value
                        });
                    });
                }
            });

            form.on('select(country)', function(data){
                var pid = data.value;
                $("#city_id").html('<option value="">请选择</option>');
                $("#region_id").html('<option value="">请选择</option>');

                var s = '<option value="">请选择</option>';
                $.ajax({
                    type: 'POST',
                    url: '{{url('/public/area/list')}}',
                    data: {pid: pid},
                    async: false,
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 200) {
                            $.each(data.data, function (i, n) {

                                var option1 = $("<option>").val(n.area_id).text(n.title);
                                $("#city_id").append(option1);
                                form.render('select');
                                //s += '<option value="' + n.area_id + '">' + n.title + '</option>';
                            });
                            // $("#city_id").html(s);
                        } else {
                            $("#city_id").html('<option value="">请选择</option>');
                            $("#region_id").html('<option value="">请选择</option>');
                        }

                    }
                });

            });


            form.on('select(city)', function(data){
                var pid = data.value;
                // $("#city_id").html('<option value="">请选择</option>');
                $("#region_id").html('<option value="">请选择</option>');

                var s = '<option value="">请选择</option>';
                $.ajax({
                    type: 'POST',
                    url: '{{url('/public/area/list')}}',
                    data: {pid: pid},
                    async: false,
                    dataType: 'json',
                    success: function (data) {
                        console.log(1111);
                        if (data.status == 200) {
                            console.log(1111);
                            $.each(data.data, function (i, n) {
                                console.log(n.area_id+'----'+n.title);
                                var option1 = $("<option>").val(n.area_id).text(n.title);
                                $("#region_id").append(option1);
                                form.render('select');
                                //s += '<option value="' + n.area_id + '">' + n.title + '</option>';
                            });
                            console.log(3333);
                            // $("#city_id").html(s);
                        } else {
                            //  $("#city_id").html('<option value="">请选择</option>');
                            $("#region_id").html('<option value="">请选择</option>');
                        }

                    }
                });

            });

        });


        $(".del").unbind("click");
        $(".del").click(function(){
            var str = $("#smeta").val();
            var delid = $(this).attr("delid");
            var sb = StringOperate.remove(str, delid);
            $("#smeta").val(sb);
            $(this).closest(".class-img").fadeOut("fast", function (){
                $(this).remove();
            });
        });
        //=============================================时间选框================================================
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //开始日期
            var insStart = laydate.render({
                elem: '#start_time'
                , type: 'datetime'
                ,value: new Date()
                , done: function (value, date) {

                }
            });


        });

        $('#icon_select').click(function () {

            var index = layer.open({
                type: 2
                , title: '选择用户:'
                , content: select_user_url
                , area: ['90%', '500px'] //宽高
                , scrollbar: false
                , cancel: function (index, layero) {
                }
            });

        });
        //上传组件
        layui.use('upload', function () {
            var $ = layui.$
                , form = layui.form
            ;
            var upload = layui.upload;
            //多图片上传
            upload.render({
                elem: '#test-upload-more'
                ,url: up_url
                ,multiple: true
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    // obj.preview(function(index, file, result){
                    //     $('#test-upload-more-list').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                    // });
                }
                ,done: function(res){
                    var show_val=$("#smeta").val();
                    var new_string = StringOperate.add(show_val,res.data.src);
                    //上传完毕
                    $("#smeta").val(new_string);
                    $('#test-upload-more-list').append('<div class="class-img"><img src="'+ res.data.src +'" alt="'+  res.data.src +'" class="layui-upload-img"><a href="javascript:void(0)" class="del"   title="移除" delid="' + res.data.src + '">X</a></div>')
                    $(".del").click(function(){
                        var str = $("#smeta").val();
                        var delid = $(this).attr("delid");
                        var sb = StringOperate.remove(str, delid);
                        $("#smeta").val(sb);
                        $(this).closest(".class-img").fadeOut("fast", function (){
                            $(this).remove();
                        });
                    });
                    layui.msg("上传成功");
                }
            });
            //拖拽上传
            upload.render({
                elem: '#test-upload-drag'
                ,url:up_url
                ,done: function(res){
                    console.log(res)
                }
            });
            //执行实例
            var uploadInst = upload.render({
                elem: '#upload_wap_img' //绑定元素
                , url: up_url //上传接口
                , field: 'file'
                , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                    layer.load(1); //上传loading
                }
                , done: function (res) {
                    if (res.status == 200) {
                        var src = res.data.src;
                        $("#upload_wap_img_val").val(src);
                    } else {
                        layer.msg(res.msg);
                    }
                    //上传完毕回调
                    layer.closeAll('loading'); //关闭loading
                }
                , error: function () {
                    //请求异常回调
                    layer.closeAll('loading'); //关闭loading
                }
            });

        });

        //====================================自动填充================================
        $( "#tags" ).autocomplete({

            source: like_url,
            minLength: 1,
            select: function( event, ui ) {
                var v=ui.item.id;
                var name=ui.item.name;
                $("#buy_select_no_text").html('<input type="hidden" name="wx_no" value="'+v+'"  />'+name);

//log( ui.item ?
                //  "Selected: " + ui.item.value + " aka " + ui.item.id :
                //  "Nothing selected, input was " + this.value );
            },
            close: function() {
                // $( "#tags" ).val("");
            }

        });


        $(document).ready(function () {
            $("#paid_amount").blur(function () {
                var paid_amount = $(this).val();
                var all_amount = $("#all_amount").val();
                var vs = (all_amount - paid_amount).toFixed(2);
                $("#collected_amount").val(vs);
                if (vs > 0) {
                    $("#noall_radio").attr("checked", true);

                } else {
                    $("#all_radio").attr("checked", true);
                }
            });
            $("#all_amount").blur(function () {
                var all_amount = $(this).val();
                var paid_amount = $("#paid_amount").val();
                var vs = (all_amount - paid_amount).toFixed(2);
                $("#collected_amount").val(vs);
                if (vs > 0) {
                    $("#noall_radio").attr("checked", true);
                } else {
                    $("#all_radio").attr("checked", true);
                }
            });
        });
    </script>
@stop
